<?php
class helper {
	public $mess;
	public $check;
	
	public function check_empty($data,$error)
	{
		if($data=="")
		{
			$this->mess[]=$error;
		}
		
	}
	public function check_email($email,$error)
	{
		$pattern="/^[a-zA-Z]{1,}[a-zA-Z0-9\_\-\.]+\@[a-zA-Z0-9]{3,}(\.[a-zA-Z]{2,})+$/";
		if(!preg_match($pattern,$email)){
			 $this->mess[]=$error;
		}
	}
	
	public function check_username($username,$error)
	{	//======6->20 letter, only alphanumeric and space
		$pattern="/^[a-zA-Z0-9_-\s]{6,20}$/";
		if(!preg_match($pattern,$username))
		{
			$this->mess[]=$error;
		}
		
	}
	
	public function check_url($url,$error)
	{
		$pattern="/^http(s)?:\/\/[a-z0-9-]+(\.[a-z0-9-]{2,})+$/i";
		if(!preg_match($pattern,$url))
		{
			$this->mess[]=$error;
		}
		
	}
	public function check_match($str1,$str2,$error)
	{
		
		if($str1!=$str2)
		{
			$this->mess[]=$error;
		}
		
	}
	public function valid()
	{
		if($this->mess != "")
		{
			$this->check=false;
		}
		else
		{
			$this->check=true;
		}
		return $this->check;
	}
}
?>